//
//  MainView.m
//  Daybook
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 zhangbin. All rights reserved.
//

#import "MainView.h"
#import "Common.h"

@interface MainView ()<UIAlertViewDelegate>

@property (nonatomic, strong) UIButton *topLeftButton;
@property (nonatomic, strong) UIButton *topRightButton;

@property (nonatomic, strong) UILabel *incomeLabel;
@property (nonatomic, strong) UILabel *expenseLabel;


@end
@implementation MainView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createTopView];
        [self createTimeTableView];
    }
    return self;
}

- (void)createTopView {
    self.backgroundColor = [UIColor whiteColor];
    
    self.topImageView = [[BaseImageView alloc] initWithFrame:CGRectMake(0, 20, MAIN_WIDTH, MAIN_HEIGHT / 3)];
    [self addSubview:_topImageView];
//    self.topImageView.image = [UIImage imageNamed:@"bookTemplateBg_5@3x.png"];
//    self.topImageView.backgroundColor = [UIColor brownColor];
    
    
    self.payAndIncomeView = [[PayAndIncomeView alloc]initWithFrame:CGRectMake(0, MAIN_HEIGHT / 3 + 20, MAIN_WIDTH, (95 / 414.0 * MAIN_WIDTH) / 2)];
    [self addSubview:self.payAndIncomeView];
    
    self.topLeftButton = ({
        UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
        tempButton.frame = CGRectMake((10 / 414.0 * MAIN_WIDTH), (MAIN_HEIGHT * (35 / 736.0)), 30 / 414.0 * MAIN_WIDTH, 30 / 414.0 * MAIN_WIDTH);
        [self addSubview:tempButton];
//        [tempButton setTitle:@"抽" forState:UIControlStateNormal];
        [tempButton setImage:[UIImage imageNamed:@"leftButton_32.png"] forState:UIControlStateNormal];
        [tempButton addTarget:self action:@selector(topLeftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//        tempButton.backgroundColor = [UIColor lightGrayColor];
//        tempButton.layer.borderWidth = 1;
//        tempButton.layer.borderColor = [[UIColor lightGrayColor]CGColor];
//        tempButton.layer.cornerRadius = (15 / 414.0 * MAIN_WIDTH);
//        tempButton.layer.masksToBounds = YES;
        tempButton;
    });
    
    self.topMiddleButton = ({
        UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
        tempButton.frame = CGRectMake(0, (MAIN_HEIGHT * (40 / 736.0)), 150 / 414.0 * MAIN_WIDTH, 30 / 414.0 * MAIN_WIDTH);
        tempButton.center = CGPointMake(MAIN_WIDTH / 2, MAIN_HEIGHT * (50 / 736.0));
        [self addSubview:tempButton];
        [tempButton setTitle:@"默认账本" forState:UIControlStateNormal];
        [tempButton addTarget:self action:@selector(topMiddleButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//        tempButton.backgroundColor = [UIColor lightGrayColor];
//        tempButton.layer.borderWidth = 1;
//        tempButton.layer.cornerRadius = (MAIN_HEIGHT * (15 / 736.0));
//        tempButton.layer.masksToBounds = YES;
//        tempButton.layer.borderColor = [[UIColor lightGrayColor]CGColor];
        tempButton;
    });
    
    self.topRightButton = ({
        UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
        tempButton.frame = CGRectMake((MAIN_WIDTH - 40 / 414.0 * MAIN_WIDTH), (MAIN_HEIGHT * (35 / 736.0)), 30 / 414.0 * MAIN_WIDTH, 30 / 414.0 * MAIN_WIDTH);
        [self addSubview:tempButton];
//        [tempButton setTitle:@"细" forState:UIControlStateNormal];
        [tempButton addTarget:self action:@selector(topRightButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//        tempButton.backgroundColor = [UIColor lightGrayColor];
//        tempButton.layer.borderWidth = 1;
//        tempButton.layer.cornerRadius = (15 / 414.0 * MAIN_WIDTH);
//        tempButton.layer.masksToBounds = YES;
//        tempButton.layer.borderColor = [[UIColor lightGrayColor]CGColor];
        [tempButton setImage:[UIImage imageNamed:@"rightButton_32.png"] forState:UIControlStateNormal];

        tempButton;
    });
    
    self.addButton = ({
        UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
        tempButton.frame = CGRectMake(0, (MAIN_HEIGHT * (200 / 736.0)), 95 / 414.0 * MAIN_WIDTH, 95 / 414.0 * MAIN_WIDTH);
        tempButton.center = CGPointMake(MAIN_WIDTH / 2, MAIN_HEIGHT * (265 / 736.0));
        [self addSubview:tempButton];
        [tempButton setImage:[UIImage imageNamed:@"add_32.png"] forState:UIControlStateNormal];
        [tempButton addTarget:self action:@selector(addButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        tempButton.backgroundColor = [UIColor whiteColor];
        tempButton.layer.borderWidth = 1;
        tempButton.layer.cornerRadius = (95 / 414.0 * MAIN_WIDTH) / 2.0;
        tempButton.layer.masksToBounds = YES;
        tempButton.layer.borderColor = [[UIColor lightGrayColor]CGColor];
        tempButton;
    });

}

- (void)createTimeTableView {
    
}

- (void)topLeftButtonAction:(UIButton *)button {
    [self.delegate topLeftButtonAction];
}

- (void)topMiddleButtonAction:(UIButton *)button {
    
}

- (void)topRightButtonAction:(UIButton *)button {
    [self.delegate topRightButtonAction];
}

- (void)addButtonAction:(UIButton *)button {
    [self.delegate addButtonAction];
}

@end
